home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Main.bin
/
ClasspathEntry.java
< prev
next >
Wrap
Text File
|
1998-11-03
|
5KB
|
230 lines
package com.symantec.itools.lang;
import java.io.IOException;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import com.symantec.itools.io.Directory;
import com.symantec.itools.io.FileSystem;
/**
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class ClasspathEntry
{
/**
* @since VCafe 3.0
*/
protected boolean isFile;
/**
* @since VCafe 3.0
*/
protected String name;
private ZipFile zipFileHandle;
public ClasspathEntry(String entry)
{
File file;
file = new File(entry);
isFile = file.isFile();
if(file.exists())
{
name = FileSystem.getCanonicalPath(file, true);
}
else
{
name = file.getName();
}
}
/**
* @since VCafe 3.0
*/
public String getName()
{
return (name);
}
/**
* @since VCafe 3.0
*/
public boolean isFile()
{
return (isFile);
}
/**
* @since VCafe 3.0
*/
public boolean isDirectory()
{
return (!(isFile));
}
/**
* @param obj TODO
* @since VCafe 3.0
*/
public boolean equals(Object obj)
{
if(obj instanceof ClasspathEntry)
{
return (((ClasspathEntry)obj).name.equals(name));
}
return (false);
}
/**
* @since VCafe 3.0
*/
public int hashCode()
{
return (name.hashCode());
}
/**
* @since VCafe 3.0
*/
public String toString()
{
return (name + " " + ((isFile) ? "file" : "directory"));
}
/**
* @param classpath TODO
* @since VCafe 3.0
*/
public Hashtable load(Classpath classpath)
{
Hashtable types;
types = new Hashtable();
try
{
String[] files;
if(isFile)
{
ZipFile zipFile;
zipFile = new ZipFile(name);
for(Enumeration e = zipFile.entries(); e.hasMoreElements();)
{
ZipEntry entry;
entry = (ZipEntry)e.nextElement();
if(!(entry.isDirectory()))
{
types.put(entry.getName(), this);
}
}
}
else
{
Directory directory;
directory = new Directory(name);
files = directory.listFiles(true);
for(int i = 0; i < files.length; i++)
{
// FIXME - need to load from directories
/*
try
{
types.put(classpath.convertResourceNameToJavaName(files[i], true).getFullName(), this);
}
catch(NotJavaNameException ex)
{
ex.printStackTrace();
}
*/
}
}
}
catch(IOException ex)
{
}
return (types);
}
/**
* @param entryName TODO
* @since VCafe 3.0
*/
public boolean find(String entryName)
{
if(isFile)
{
try
{
return (getZipFile(name).getEntry(entryName) != null);
}
catch(IOException ex)
{
return (false);
}
}
return (new File(FileSystem.getCanonicalPath(name, true) + entryName.replace('/', File.separatorChar)).exists());
}
protected ZipFile getZipFile(String name)
throws IOException
{
if(zipFileHandle == null)
{
zipFileHandle = new ZipFile(name);
}
return (zipFileHandle);
}
public void cleanup()
{
if(zipFileHandle != null)
{
try
{
zipFileHandle.close();
}
catch(IOException ex)
{
Debug.logException(ex);
}
zipFileHandle = null;
}
}
protected void finalize()
throws Throwable
{
super.finalize();
cleanup();
}
}